package usejava.threadpool;

import java.util.concurrent.*;

public class ConstractThreadPoolLock {

    public ConstractThreadPoolLock() {

    }

    public static void main(String[] args) {
        int corePoolSize = 5;
        int maximumPoolSize = 10;
        long keepAliveTime = 120;
        TimeUnit unit = TimeUnit.SECONDS;
        BlockingQueue<Runnable> workQueue = new ArrayBlockingQueue<>(100);
        ThreadFactory threadFactory = new MyThreadFactory();
        RejectedExecutionHandler handler = new MyRejectedExecutionHandler();

        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(corePoolSize,maximumPoolSize,
                keepAliveTime, unit, workQueue, threadFactory, handler);



        threadPoolExecutor.execute(new Runnable() {
            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName() + " is running a task.");
            }
        });

        threadPoolExecutor.shutdown();
    }
}
